import { err, to, toast } from "~/utils/wxapi";
import { NoticeList, DelNotice } from "~/apis/notice";
Page({
  data: { list: [] },
  onShow() {
    this.getlist();
  },
  async getlist() {
    try {
      const res: any = await NoticeList();
      console.log(res);
      if (res.code === 200) {
        this.setData({ list: res.data.item });
      }
    } catch (error) {
      console.log(error);
      err(error);
    }
  },
  togg() {
    to("/pages/addNot/addNot");
  },
  put(e: any) {
    const { id } = e.currentTarget.dataset;
    to("/pages/addNot/addNot?id=" + id);
  },
  del(e: any) {
    const { id } = e.currentTarget.dataset;
    wx.showModal({
      title: "提示",
      content: "您确定删除该公告吗？",
      complete: async (resp: any) => {
        if (resp.confirm) {
          const res: any = await DelNotice(id);
          if (res.code === 200) {
            toast(res.message);
            this.getlist();
          } else {
            toast(res.message);
          }
        }
      },
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  async onPullDownRefresh() {
    await this.getlist();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() { },
});
